<template>
	<view style="width: 100%;height: 100%;">
		<uni-popup ref='popup' type="center" border-radius="10px">
			<view class="gl-popup-view">
				<view class="gl-popup-title">
					<view class=""> 修改会员权益 </view>
					<uni-icons class="gl-button-mini gl-button-error" type="closeempty" size="18" color="#fff"
						@tap="EventClose"></uni-icons>
				</view>
				<view class="gl-popup-body">
					<view class="" style="display: flex;">
						<uni-data-select class="gl-data-select" v-model="curLevel" :localdata="levelList" emptyTips="没有"
							label="变更会员权益" placeholder="选择会员权益" style="width: 250px;"
							@change="levelChange"></uni-data-select>
					</view>
				</view>
				<view class="gl-popup-foot" style="display: flex;justify-content: flex-end;gap: 10px;">
					<view class="gl-button gl-button-base" @tap="EventSubmit">
						<uni-icons type="checkmarkempty" size="18" color="#fff"></uni-icons>
						<text style="font-size: small;">保存</text>
					</view>
					<view class="gl-button gl-button-warning" @tap="EventClose">
						<uni-icons type="closeempty" size="18" color="#fff"></uni-icons>
						<text style="font-size: small;">取消</text>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import psMethod from '@/common/psMethod'
	import utils from '@/common/utils'
	export default {
		data() {
			return {
				sConf: getApp().globalData,
				curStaff: null,
				curLevel: 0,
				levelList: []
			}
		},
		mounted() {
			this.loadLevelList()
		},
		methods: {
			EventClose() {
				this.$refs.popup.close()
			},
			open(e) {
				// console.log(e);
				this.curStaff = e
				this.curLevel = e.sub_curlevel ? e.sub_curlevel.level : 1
				this.$refs.popup.open()
			},
			EventSubmit() {
				console.log('EventSubmit');
				let that = this
				uni.showModal({
					title: '变更权益',
					content: '是否要变更权益',
					success(r) {
						if (r.confirm) {
							that.loadLevelEdit()
						}
					}
				})
			},
			loadLevelEdit() {
				let host = this.sConf.host + '/admin/levelEdit/'
				let token = this.sConf.auth.token || ''
				let data = {
					sid: this.curStaff.id,
					level: this.curLevel
				}
				psMethod.authenticatorPostSync(host, token, data).then(res => {
					console.log('编辑权益', res);
					this.$emit('reload')
					this.EventClose()
				})
			},
			loadLevelList() {
				let host = this.sConf.host + '/admin/level/'
				let token = this.sConf.auth.token || ''
				let data = {
					status: 1,
					ordering: 'level'
				}
				psMethod.authenticatorGetSync(host, token, data).then(res => {
					console.log('会员权益', res);
					let tmpData = []
					res.resmsg.forEach(item => {
						tmpData.push({
							value: item.level,
							text: item.name
						})
					})
					this.levelList = tmpData;
				})
			},
			levelChange(e) {
				console.log('levelChange', e, this.curLevel);
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>